<template>
  <el-card header="基本信息">
    <el-form ref="memberForm" :model="memberForm" :rules="rules" label-width="120px" :disabled="flowData.readOnly">
      <el-form-item hidden>
        <el-input v-model="memberForm.memberId" hidden />
      </el-form-item>
      <el-form-item label="用户名称" prop="userName">
        <el-input v-model="memberForm.userName" />
      </el-form-item>
      <el-form-item label="会员级别" prop="memberLevel">
        <el-select v-model="memberForm.memberLevel" @change="handleUpdateInfo">
          <el-option
            v-for="item in memberLevels"
            :key="item.dictCode"
            :label="item.dictLabel"
            :value="item.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item v-if="!flowData.readOnly && !flowData.firstNode">
        <el-radio v-model="memberForm.pass" label="0" @click="handleUpdateInfo">通过</el-radio>
        <el-radio v-model="memberForm.pass" label="1" @click="handleUpdateInfo">不通过</el-radio>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
export default {
  name: 'MemberForm',
  props: {
    info: {
      type: Object,
      default: () => {
        return {
          memberId: undefined,
          userId: undefined,
          userName: undefined,
          memberLevel: undefined,
          pass: '0'
        }
      }
    },
    flowData: {
      type: Object,
      default: () => {
        return {
          processName: undefined,
          processDefinitionId: undefined,
          processInstanceId: undefined,
          executionId: undefined,
          startUser: undefined,
          currentUserId: undefined,
          currentUser: undefined,
          taskId: undefined,
          firstNodeId: undefined,
          currentNodeId: undefined,
          currentNodeName: undefined,
          firstNode: true,
          firstSubmit: false,
          nextNodeNum: 0,
          nextNodes: [],
          nextUser: undefined,
          targetNodeId: undefined,
          readOnly: true
        }
      }
    }
  },
  data() {
    return {
      memberForm: {
        memberId: undefined,
        userId: undefined,
        userName: undefined,
        memberLevel: undefined,
        pass: '0'
      },
      memberLevels: [],
      rules: {}
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      this.memberForm = this.$api.objectUpdate(this.memberForm, this.info)
      this.memberForm.pass = '0'
      this.memberForm.memberLevel = this.memberForm.memberLevel !== undefined ? this.memberForm.memberLevel + '' : undefined
      this.$emit('update:info', this.memberForm)
      this.getDictData()
    },
    getDictData() {
      this.$http.get('/admin/system/dict/dictGroup?group=member_level').then(response => {
        this.memberLevels = response
      }).catch(e => {})
    },
    handleUpdateInfo() {
      this.$emit('update:info', this.memberForm)
    }
  }
}
</script>
